insert
    overwrite
    table jms_dm.dm_sqs_project_customer_summary_dt
    partition
    (dt)
select project_first_type_code  as project_first_type_code  --项目一级编码
     , project_first_type_name  as project_first_type_name  --项目一级名称
     , project_second_type_name as project_second_type_name --项目二级名称
     , customer_code            as customer_code            --客户编码
     , customer_name            as customer_name            --客户名称
     , count(1)                 as taking_num               --揽收量
     , sum(complaint_flag)      as complaint_num            --客诉量
     , sum(sham_flag)           as sham_num                 --虚假签收量
     , sum(delay_flag)          as delay_num                --延误量
     , sum(worn_flag)           as worn_num                 --破损量
     , date_time                as date_time                --录入时间
     , dt                       as dt                       --录入时间
from jms_dm.dm_sqs_project_customer_waybill_detail_dt
where dt <= '{{ execution_date | cst_ds }}'
  and dt >= date_add('{{ execution_date | cst_ds }}', -6)
group by project_first_type_code
       , project_first_type_name
       , project_second_type_name
       , customer_code
       , customer_name
       , date_time
       , dt
    distribute by dt
;